<!--订单汇总-->
<?php echo $this->render('/public/header'); ?>
<script src="https://cdn.bootcss.com/element-ui/2.1.0/index.js"></script>
<link href="https://cdn.bootcss.com/element-ui/2.0.2/theme-chalk/index.css" rel="stylesheet">
<div id="main" class="col-xs-12">
    <div style="float:right">
        <b>注意事项</b><br/>
        <b>1.订单在未结算之前，数据不一定正确</b>
    </div>
    <form action="" method="get">
        <div class="form-inline">
            <div class="form-group">
                <select class="form-control" name="job_number">
                    <option value=0>--请选择--</option>
                    <?php foreach ($this->params['staff_list'] as $k => $v): ?>
                        <option value="<?php echo $v['job_number']; ?>"
                            <?php if (yii::$app->request->get('job_number') == $v['job_number']): ?>
                                <?php echo 'selected'; ?>
                            <?php endif;?>
                        ><?php echo $v['name']; ?>
                        </option>
                    <?php endforeach;?>
                </select>
            </div>
            <div class="form-group">
                <select class="form-control" name="purchase">
                    <option value=0>--采购--</option>
                    <?php foreach ($this->params['staff_list'] as $k => $v): ?>
                        <option value="<?php echo $v['job_number']; ?>"
                            <?php if (yii::$app->request->get('purchase') == $v['job_number']): ?>
                                <?php echo 'selected'; ?>
                            <?php endif;?>
                        ><?php echo $v['name']; ?>
                        </option>
                    <?php endforeach;?>
                </select>
            </div>
            <div class="form-group">
                <input type="text" class="form-control" name="invoice" placeholder="请输入invoice编号"
                       value="<?php echo yii::$app->request->get('invoice'); ?>"
                >
            </div>
            <div class="form-group">
                <input type="text" class="form-control" name="customer_name" placeholder="请输入客户名称"
                       value="<?php echo yii::$app->request->get('customer_name'); ?>">
            </div>
            <div class="form-group">
                <input type="text" placeholder="开始时间" name="begin_date" class="form-control form_datetime"
                       value="<?php echo yii::$app->request->get('begin_date'); ?>"/>
            </div>
            <div class="form-group">
                <input type="text" placeholder="结束时间" name="end_date" class="form-control form_datetime"
                       value="<?php echo yii::$app->request->get('end_date'); ?>"/>
            </div>
            <div class="form-group">
                <select class="form-control" name="recommend" style="width:200px">
                    <option value="0">推荐人</option>
                    <?php foreach ($this->params['referList'] as $v): ?>
                        <option value="<?php echo $v['id']; ?>" <?php echo yii::$app->request->get('recommend') == $v['id'] ? 'selected' : ''; ?>><?php echo $v['name']; ?></option>
                    <?php endforeach;?>
                </select>
            </div>
            <div class="form-group">
                <select name="invoice_status" class="form-control">
                    <option value=0>订单状态</option>
                    <?php foreach ($this->params['invoice_status'] as $k => $v): ?>
                        <option value=<?php echo $k; ?> <?php if (yii::$app->request->get('invoice_status') == $k) {
    echo 'selected';
}?>><?php echo $v; ?></option>
                    <?php endforeach?>
                </select>
            </div>
            <br/>
            <br/>
            <div class="form-group">
                <select class="form-control" name="order_status">
                    <option value="0">订单状态</option>
                    <?php foreach (yii::$app->params['order_status'] as $k => $v): ?>
                        <option value="<?php echo $k; ?>" <?php echo yii::$app->request->get('order_status') == $k ? 'selected' : ''; ?>><?php echo $v; ?></option>
                    <?php endforeach;?>
                </select>
            </div>
            <div class="form-group">
                <select class="form-control" name="is_jiesuan">
                    <option value="0" <?php if (yii::$app->request->get('is_jiesuan') == 0) {
    echo 'selected';
}?>>是否结算
                    </option>
                    <option value="1" <?php if (yii::$app->request->get('is_jiesuan') == 1) {
    echo 'selected';
}?>>未结算
                    </option>
                    <option value="2" <?php if (yii::$app->request->get('is_jiesuan') == 2) {
    echo 'selected';
}?>>财务审核
                    </option>
                    <option value="3" <?php if (yii::$app->request->get('is_jiesuan') == 3) {
    echo 'selected';
}?>>已结算
                    </option>
                </select>
            </div>
            <div class="form-group">
                <input placeholder="结算开始时间" type="text" placeholder="结算日期" name="confirm_begin_date"
                       class="form-control form_datetime"
                       value="<?php echo yii::$app->request->get('confirm_begin_date'); ?>"/>
            </div>
            <div class="form-group">
                <input placeholder="结算结束时间" type="text" name="confirm_end_date" class="form-control form_datetime"
                       value="<?php echo yii::$app->request->get('confirm_end_date'); ?>"/>
            </div>
            <div class="form-group">
                <button class="btn btn-success">提交</button>
            </div>

        </div>
    </form>
    <br/>
    <button class="btn btn-danger" onclick="show()">显示未录入invoice</button>
    <button class="btn btn-success" onclick="download()">下载excel</button>
    <br/>
    <div style="display: none" id="showin">
        <ul class="nav nav-pills" role="tablist">
            <?php foreach ($this->params['notUseList'] as $v): ?>
                <li role="presentation" class="active" style="margin: 10px 10px"><span
                            class="label label-default"><?php echo $v['invocie_num']; ?></span></li>
            <?php endforeach;?>
        </ul>
    </div>
    <div><span class="label label-default">重复录入invoice</span>
        <ul class="nav nav-pills" role="tablist">
            <?php foreach ($this->params['sameInvoice'] as $v): ?>
                <li role="presentation" class="active" style="margin: 10px 10px"><span
                            class="label label-default"><?php echo $v['invoice']; ?></span></li>
            <?php endforeach;?>
        </ul>
    </div>

    <br/>
    <div id="table">
        <el-switch
                v-model="invoice"
                @change="(v)=>change(v,1)"
                active-color="#13ce66"
                inactive-color="#ff4949"
                active-text="显示in"
                inactive-text="关闭in">
        </el-switch>
        <el-switch
                v-model="pi"
                @change="(v)=>change(v,2)"
                active-color="#13ce66"
                inactive-color="#ff4949"
                active-text="显示pi"
                inactive-text="关闭pi">
        </el-switch>
        <el-switch
                v-model="customer_num"
                @change="(v)=>change(v,3)"
                active-color="#13ce66"
                inactive-color="#ff4949"
                active-text="显示客户编号"
                inactive-text="关闭客户编号">
        </el-switch>
        <el-switch
                v-model="customer_name"
                @change="(v)=>change(v,4)"
                active-color="#13ce66"
                inactive-color="#ff4949"
                active-text="显示客户名称"
                inactive-text="关闭客户名称">
        </el-switch>
        <el-switch
                v-model="product"
                @change="(v)=>change(v,8)"
                active-color="#13ce66"
                inactive-color="#ff4949"
                active-text="显示产品"
                inactive-text="关闭产品">
        </el-switch>
        <el-switch
                v-model="remark"
                @change="(v)=>change(v,12)"
                active-color="#13ce66"
                inactive-color="#ff4949"
                active-text="显示备注"
                inactive-text="关闭备注">
        </el-switch>
    </div>
    <div>
        <table class="table" style="overflow-y:scroll ">
            <thead>
            <tr>
                <th style="width:50px">日期</th>
                <th style="width:90px;">invoice</th>
                <th style="width:90px;">pi</th>
                <th style="width:70px">客户编号</th>
                <th style="width:80px">客户名称</th>
                <td style="width:80px">客户来源</td>
                <th style="width:50px">业务员</th>
                <th style="width:50px">采购</th>
                <th style="width:70px">采购</th>
                <th style="width:80px">产品</th>
                <th style="width:60px">invoice总金额</th>
                <th style="width:60px">收货验货</th>
                <th style="width:60px">收款状态</th>
                <th style="width:60px">出货时间</th>
                <th style="width:60px">收入</th>
                <th style="width:60px">差额</th>
                <th style="width:70px">备注</th>
                <th style="width:60px">运费</th>
                <th style="width:60px">打印费</th>
                <th style="width:60px">仓库费</th>
                <th style="width:60px">大货</th>
                <th style="width:60px">报销</th>
                <th style="width:60px">其他</th>
                <th style="width:60px">内陆费</th>
                <th style="width:35px">美元汇率</th>
                <th style="width:60px">利润</th>
                <th style="width:60px">利润率</th>
                <th style="width:60px">业务员提成</th>
                <th style="width:60px">采购提成</th>
                <th style="width:80px">订单状态</th>
                <th style="width:80px">是否结算</th>
                <th style="width:100px">结算时间</th>
                <th style="width:100px">订单性质</th>
                <?php if ($role == 1): ?>
                    <th style="width:100px">开启比例结算</th>
                    <th style="width:100px">结算比例</th>
                <?php endif;?>
                <th style="width:60px">详情</th>
            </tr>
            </thead>
            <tbody>
            <?php foreach ($list['list'] as $k => $v): ?>
                <tr>
                    <td><?php echo $v['date']; ?></td>
                    <td><?php echo $v['invoice']; ?></td>
                    <td><?php echo $v['pi']; ?></td>
                    <td><?php echo $v['customer_num']; ?></td>
                    <td><p style="<?php if (isset($v['isSame']) && !$v['isSame']) {
    echo 'color:red';
}?>"><?php echo $v['customer_name']; ?></p></td>
                    <td>
                        <?php foreach ($this->params['referList'] as $v2): ?>
                            <?php if ($v['recommend'] == $v2['id']): ?>
                                <?php echo $v2['name']; ?>
                            <?php endif;?>
                        <?php endforeach;?>
                    </td>
                    <td><?php echo $v['saleman']; ?></td>
                    <td><?php if (isset($v['purchase_name'])): ?>
                            <?php foreach ($this->params['staff_list'] as $v2): ?>
                                <?php if ($v2['job_number'] == $v['purchase_name']) {
    echo $v2['name'];
    break;
}
;?>
                            <?php endforeach;?>
                        <?php endif;?>
                    </td>
                    <td>
                        <select class="form-control" style="border:none;padding: 0"
                                onchange="update_order_pay(<?php echo $v['id']; ?>,'purchase',this)">
                            <option value="0">请选择</option>
                            <?php foreach ($this->params['staff_list'] as $v2): ?>
                                <option <?php if ($v2['job_number'] == $v['purchase']) {
    echo 'selected';
}?> value="<?php echo $v2['job_number']; ?>"><?php echo $v2['name']; ?></option>
                            <?php endforeach;?>
                        </select>
                    </td>
                    <td><input style="padding: 0px;border: none" class="form-control"
                               onchange="update_order_pay(<?php echo $v['id']; ?>,'product',this)" type="text"
                               value="<?php echo $v['product']; ?>"/></td>
                    <td><input <?php echo in_array($this->params['admin_role'], [1, 2]) ?: "disabled"; ?>
                                style="width:100%;border:none" type="text"
                                onchange="update_order_pay(<?php echo $v['id']; ?>,'order_pay',this)"
                                value="<?php echo $v['order_pay']; ?>"/></td>
                    <td>
                        <select style="width:100%;padding: 0" class="form-control"
                                onchange="update_order_pay(<?php echo $v['id']; ?>,'is_receive',this)">
                            <option value="0">请选择</option>
                            <option value="1" <?php echo $v['is_receive'] == 1 ? 'selected' : ''; ?>>正常</option>
                            <option value="2" <?php echo $v['is_receive'] == 2 ? 'selected' : ''; ?>>收货验货</option>
                        </select>
                    </td>
                    <td>
                        <select style="width:100%;padding: 0" class="form-control"
                                onchange="update_order_pay(<?php echo $v['id']; ?>,'pay_status',this)">
                            <option value="0">请选择</option>
                            <option value="1" <?php echo $v['pay_status'] == 1 ? 'selected' : ''; ?>>未付款</option>
                            <option value="2" <?php echo $v['pay_status'] == 2 ? 'selected' : ''; ?>>已付定金</option>
                            <option value="3" <?php echo $v['pay_status'] == 3 ? 'selected' : ''; ?>>已结尾款</option>
                        </select>
                    </td>
                    <td>
                       <input type="text" style="padding:0;border:none" class="form-control form_datetime"
                               value="<?php echo $v["chuhuo_date"] == '0000-00-00' ? '' : $v['chuhuo_date']; ?>"
                               onchange="update_order_pay(<?php echo $v['id']; ?>,'chuhuo_date',this)"/>
                    </td>
                    <td><a target="__blank"
                           href="/table/income?invocie=<?php echo $v['invoice']; ?>"><?php echo $v['clean']; ?></a></td>
                    </td>

                    <td><span <?php if ($v['clean'] - $v['order_pay'] < 0) {
    echo "style='color:red'";
}?>><?php echo round($v['clean'] - $v['order_pay'], 2); ?></span></td>
                    <td><?php echo $v['remark']; ?></td>
                    <td>
                        <a target="__blank"
                           href="/table/express_list?invoice=<?php echo $v['invoice']; ?>"><?php echo $v['express_fee'] ?></a>
                    </td>
                    <td><?php echo $v['print_fee']; ?></td>
                    <td>
                        <a target="__blank"
                           href="/table/repo?invoice_order=<?php echo $v['invoice']; ?>"><?php echo $v['repo_fee']; ?></a>
                    </td>
                    <td>
                        <a target="__blank"
                           href="/table/bank?invocie=<?php echo $v['invoice']; ?>&type=<?php echo $v['saleman_num'] > 2 ? 1 : 28; ?>"><?php echo $v['bank']; ?></a>
                    </td>
                    <td><a target="__blank"
                           href="/finance/reimburse?invoice=<?php echo $v['invoice']; ?>"><?php echo $v['baoxiao']; ?></a>
                    </td>
                    <td><?php echo $v['others']; ?></td>
                    <td>
                        <a target="__blank"
                           href="/table/inland?invoice=<?php echo $v['invoice']; ?>"><?php echo $v['inland_fee']; ?></a>
                    </td>
                    <td><?php echo $v['exchange_rate']; ?></td>
                    <td><p style="<?php echo $v['lirun'] < 0 ? 'color:red' : ''; ?>"><?php echo $v['lirun']; ?></p></td>
                    <td>
                        <p style="<?php echo $v['lirun'] < 0 ? 'color:red' : ''; ?>"><?php echo $v['clean'] ? round(($v['lirun'] / ($v['clean'] * $v['exchange_rate'])) * 100, 2) . '%' : 0; ?></p>
                    </td>
                    <td><?php echo $v['saleman_get']; ?></td>
                    <td><?php echo $v['purchase_get']; ?></td>
                    <td>
                        <select class="form-control"
                                style="border:none;padding:0"
                                onchange="update_order_pay(<?php echo $v['id']; ?>,'invoice_status',this)">
                            <option value=0>请选择</option>
                            <?php foreach ($this->params['invoice_status'] as $k2 => $v2): ?>
                                <option value=<?php echo $k2; ?> <?php if ($v['invoice_status'] == $k2) {
    echo 'selected';
}?>><?php echo $v2; ?></option>
                            <?php endforeach?>
                        </select>
                    </td>
                    <td>
                        <select class="form-control" style="border:none;padding:0"
                                onchange="update_order_pay(<?php echo $v['id']; ?>,'is_jiesuan',this)">
                            <option value="1" <?php if ($v['is_jiesuan'] == 1) {
    echo 'selected';
}
;?>>未结算
                            </option>
                            <option value="2" <?php if ($v['is_jiesuan'] == 2) {
    echo 'selected';
}
;?>>财务审核中
                            </option>
                            <option value="3" <?php if ($v['is_jiesuan'] == 3) {
    echo 'selected';
}
;?>>已结算
                            </option>
                        </select>
                    </td>
                    <td><input type="text" style="padding:0;border:none" class="form-control form_datetime"
                               value="<?php echo $v["confirm_date"] == '0000-00-00' ? '' : $v['confirm_date']; ?>"
                               onchange="update_order_pay(<?php echo $v['id']; ?>,'confirm_date',this)"/></td>
                    <td>
                        <select style="border:none" class="form-control"
                                onchange="update_order_pay(<?php echo $v['id']; ?>,'order_status',this)">
                            <?php foreach (yii::$app->params['order_status'] as $k2 => $v2): ?>
                                <option value="<?php echo $k2; ?>" <?php if ($v['order_status'] == $k2) {
    echo 'selected';
}?>><?php echo $v2; ?></option>
                            <?php endforeach;?>
                        </select>
                    </td>
                    <?php if ($role == 1): ?>
                        <td>
                            <select class="form-control" name="rate_status"
                                    onchange="update_order_pay(<?php echo $v['id']; ?>,'rate_status',this)">
                                <option value="1" <?php echo $v['rate_status'] == 1 ? 'selected' : ''; ?>>是</option>
                                <option value="2" <?php echo $v['rate_status'] != 1 ? 'selected' : ''; ?>>否</option>
                            </select>
                        </td>
                        <td>
                            <select class="form-control" name="rale_rate"
                                    onchange="update_order_pay(<?php echo $v['id']; ?>,'rale_rate',this)">
                                <option value="5" <?php echo $v['rale_rate'] == 5 ? 'selected' : ''; ?>>5%</option>
                                <option value="10" <?php echo $v['rale_rate'] == 10 ? 'selected' : ''; ?>>10%</option>
                                <option value="15" <?php echo $v['rale_rate'] == 15 ? 'selected' : ''; ?>>15%</option>
                                <option value="20" <?php echo $v['rale_rate'] == 20 ? 'selected' : ''; ?>>20%</option>
                            </select>
                        </td>
                    <?php endif;?>
                    <td>
                        <a target="__blank"
                           href="/table/order_detail?invoice=<?php echo $v['invoice']; ?>&rate=<?php echo $v['exchange_rate']; ?>"
                           class="btn btn-success" style="width:50px">详情</a>
                    </td>
                </tr>
                <?php if(isset($v['children'])):?>
                    <tr>
                        <td colspan="14">结算订单锁定数据</td>
                        <td><?php echo $v['children']['real_income'];?></td>
                        <td colspan="2"></td>
                        <td><?php echo $v['children']['express_fee'];?></td>
                        <td><?php echo $v['children']['print_fee'];?></td>
                        <td><?php echo $v['children']['repo_fee'];?></td>
                        <td><?php echo $v['children']['product_fee'];?></td>
                        <td><?php echo $v['children']['reimburse'];?></td>
                        <td><?php echo $v['children']['others'];?></td>
                        <td><?php echo $v['children']['inland_fee'];?></td>
                    </tr>
                <?php endif;?>
            <?php endforeach;?>
            <tr>
                <td colspan="9"></td>
                <td><?php echo $tmp1 = $total['totalOrderPay']; ?></td>
                <?php $tmp2          = $total['totalIncome'];?>
                <?php $tmp3          = $total['totalPay'];?>
                <?php $tmp4          = $total['totalFee'];?>
                <td><?php echo $tmp5 = $tmp2 + $tmp3 + $tmp4; ?></td>
                <td><?php echo round($tmp5 - $tmp1, 2); ?></td>
                <td></td>
                <td><?php echo $total['totalShip']; ?></td>
                <td><?php echo $total['totalPrint']; ?></td>
                <td><?php echo $total['totalRepo']; ?></td>
                <td><?php echo $total['totalBank']; ?></td>
                <td></td>
                <td><?php echo $total['totalOthers']; ?></td>
                <td><?php echo $total['totalInland']; ?></td>
                <td></td>
                <td><?php echo $total['totalProfit']; ?></td>
                <td></td>
                <td><?php echo round($total['totalSaleman'], 2); ?></td>
                <td><?php echo round($total['totalPurchase'], 2); ?></td>
            </tr>
            </tbody>
        </table>
    </div>
    <div id="page" style="display: inline-block;"></div>
    <div style="display: inline-block;line-height: 55px">共<?php echo $this->params['pagecount']; ?>条记录</div>
</div>
<script>
    new Vue({
        el: "#table",
        data: {
            invoice: true,
            pi: true,
            customer_num: true,
            customer_name: true,
            product: true,
            remark: true,
        },
        methods: {
            change: function (v, col) {
                if (v) {
                    $("tr").find("td:eq(" + col + ")").show();
                    $("tr").find("th:eq(" + col + ")").show();
                } else {
                    $("tr").find("th:eq(" + col + ")").hide();
                    $("tr").find("td:eq(" + col + ")").hide();

                }

            }
        }
    })
</script>
<script type="text/javascript">
    $(function () {
        $(".form_datetime").datepicker({format: 'yyyy-mm-dd'});
    });

    function show() {
        $("#showin").toggle();
    }

    layui.laypage({
        cont: 'page'
        , pages: <?php echo $this->params['page']['page']; ?>
        , curr:<?php echo $this->params['page']['curr']; ?>
        , skin: '#5FB878'
        , skip: true
        , jump: function (obj, first) {
            if (!first) {
                if (window.location.search) {
                    window.location.href = "<?php echo $this->params['page']['base_url']; ?>&p=" + obj.curr;
                }
                else {
                    window.location.href = "<?php echo $this->params['page']['base_url']; ?>?p=" + obj.curr;
                }

            }
        }
    });

    function download() {
        var url = '/download/download-order' + window.location.search;
        window.location.href = url;
    }

    function update_order_pay(id, column, e) {
        var url = '/table/update_order_pay';
        layer.confirm('确认修改', {}, function () {
            var value = $(e).val();
            $.post(url, {id: id, column: column, v: value}, function (res) {
                if (res.code == 1) {
                    layer.alert(res.msg);
                }
                else {
                    layer.alert(res.msg);
                }
            }, 'json')
        })
    }
</script>
<?php echo $this->render('/public/footer'); ?>
